﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace BackOffice
{
    public partial class Survey_Report2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string vendor = Request.QueryString["Vendor"];
                string datefrom = Session["datefrom"].ToString() + " 00:00:00.000";
                string dateto = Session["dateto"].ToString() + " 23:59:59.998";
                txtDateFrom.Text = Session["datefrom"].ToString();
                txtDateTo.Text = Session["dateto"].ToString();

                DataTable dt = Report.Survey_Report2(vendor, datefrom, dateto);

                Survey_Report2_Grid.DataSource = dt;
                Survey_Report2_Grid.DataBind();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string vendor = "";
            string dateFrom = "";
            string dateTo = "";

            vendor = txtVendor.Text;

            if(txtDateFrom.Text != "")
                dateFrom = txtDateFrom.Text + " 00:00:00.000";

            if(txtDateTo.Text != "")
                dateTo = txtDateTo.Text + " 23:59:59.998";

            DataTable dt = Report.Survey_Report2(vendor, dateFrom, dateTo);

            Survey_Report2_Grid.DataSource = dt;
            Survey_Report2_Grid.DataBind();
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;

            string year = dt.Year + "";
            string month = dt.Month + "";
            string day = dt.Day + "";
            string fileName = "Suvey_Report_Details" + year + month + day;
            GridViewExportUtil.Export(fileName + ".xls", this.Survey_Report2_Grid);
        }
    }
}